import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { MulterModule } from '@nestjs/platform-express';
import { diskStorage } from 'multer';
@Module({
  imports: [
    MulterModule.register({
      limits: {
        fileSize: 1024 * 1024 * 5,
      },
      fileFilter: (_req, file: Express.Multer.File, cb) => {
        // 限制上传图片类型文件
        if (file.mimetype.match(/(jpg|jpeg|png|gif)$/)) {
          return cb(null, true);
        }

        return cb(null, false);
      },
      storage: diskStorage({
        destination: './public',
        filename: (req, file, cb) => {
          // 使用原始文件名和扩展名
          const originalFilename = `${Date.now()}-${file.originalname}`;
          cb(null, originalFilename);
        },
      }),
    }),
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}
